﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//
//This is a class hold any settings in the game, it is a singleton so it can be used by all of the forms
//you can put anything that you would like in here
namespace SpotIt
{
    public class Settings
    {
        private static readonly Settings instance = new Settings();
        public double musicVolume;
        public double soundEffectsVolume;
        public double buttonBeepVolume;
        public bool soundOn;
        public bool musicOn;
        public bool soundEffectsOn;
        public bool buttonBeepOn;
        string fileName;
        public Settings() 
        {
            musicVolume = 1;
            soundEffectsVolume = 1;
            buttonBeepVolume = 1;
            fileName = "SpotIt.programSettings.txt";
            soundOn = true;
            musicOn = true;
            soundEffectsOn = true;
            buttonBeepOn = true;
        }
        public static Settings Instance
        {
            get
            {
                return instance;
            }
        }
        public void readPreviousSettings()
        {
            string line;

            //
            // Read the file and display it line by line.
            StreamReader file = new StreamReader("spotIt.programSettings.txt");
            line = file.ReadLine();
            if (line == "1")
                soundOn = true;
            else
                soundOn = false;
            line = file.ReadLine();
            if (line == "1")
                musicOn = true;
            else
                musicOn = false;
            line = file.ReadLine();
            if (line == "1")
                soundEffectsOn = true;
            else
                soundEffectsOn = false;
            line = file.ReadLine();
            if (line == "1")
                buttonBeepOn = true;
            else
                buttonBeepOn = false;
            line = file.ReadLine();
            double.TryParse(line, out musicVolume);
            line = file.ReadLine();
            double.TryParse(line, out soundEffectsVolume);
            line = file.ReadLine();
            double.TryParse(line, out buttonBeepVolume);

            file.Close();
        }
        public void saveSettings()
        {
            if (soundOn)
                File.WriteAllText(fileName, "1" + System.Environment.NewLine);
            else
                File.WriteAllText(fileName, "0" + System.Environment.NewLine);
            if (musicOn)
                File.AppendAllText(fileName, "1" + System.Environment.NewLine);
            else                                
                File.AppendAllText(fileName, "0" + System.Environment.NewLine);
            if (soundEffectsOn)                  
                File.AppendAllText(fileName, "1" + System.Environment.NewLine);
            else                                 
                File.AppendAllText(fileName, "0" + System.Environment.NewLine);
            if (buttonBeepOn)                    
                File.AppendAllText(fileName, "1" + System.Environment.NewLine);
            else
                File.AppendAllText(fileName, "0" + System.Environment.NewLine);
            File.AppendAllText(fileName, musicVolume.ToString() + System.Environment.NewLine);
            File.AppendAllText(fileName, soundEffectsVolume.ToString() + System.Environment.NewLine);
            File.AppendAllText(fileName, buttonBeepVolume.ToString() + System.Environment.NewLine);
        }
    }
}
